//
//  HYMoreBtn.m
//  HaiYue
//
//  Created by skyline on 2018/5/23.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYMoreBtn.h"
@interface HYMoreBtn ()
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UIButton *textBtn;
@property (nonatomic, strong) HYButton *imgBtn;
@end
@implementation HYMoreBtn
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.line.hidden = NO;
    }
    return self;
}

- (UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc] init];
        _line.backgroundColor = CELL_LINE_COLOR;
        [self addSubview:_line];
        [_line mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.centerY.equalTo(self);
            make.height.mas_offset(1);
            make.right.equalTo(self.textBtn.mas_left).with.offset(-3);
        }];
    }
    return _line;
}

- (UIButton *)textBtn
{
    if (!_textBtn)
    {
        _textBtn = [[UIButton alloc] init];
        [_textBtn setTitle:@"更多" forState:UIControlStateNormal];
        [_textBtn setTitle:@"隐藏" forState:UIControlStateSelected];
        [_textBtn setTitleColor:TEXT_GRAY_COLOR forState:UIControlStateNormal];
        [_textBtn setTitleColor:TEXT_GRAY_COLOR forState:UIControlStateSelected];
        _textBtn.titleLabel.font = [UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight];
        [_textBtn addTarget:self action:@selector(actionForSubMoreBtn) forControlEvents:UIControlEventTouchUpInside];
        CGSize size = [_textBtn.titleLabel.text sizeWithAttributes:@{NSFontAttributeName:_textBtn.titleLabel.font}];
        [self addSubview:_textBtn];
        [_textBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.imgBtn.mas_left);
            make.top.equalTo(self);
            make.bottom.equalTo(self);
            make.width.mas_offset(ceil(size.width));
        }];
    }
    return _textBtn;
}

- (HYButton *)imgBtn
{
    if (!_imgBtn)
    {
        _imgBtn = [[HYButton alloc] init];
        [_imgBtn setImage:[UIImage imageNamed:@"more"] forState:UIControlStateNormal];
        [_imgBtn setImage:[UIImage imageNamed:@"suojin"] forState:UIControlStateSelected];
        [_imgBtn addTarget:self action:@selector(actionForSubMoreBtn) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_imgBtn];
        [_imgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self);
            make.centerY.equalTo(self);
            make.size.mas_offset(CGSizeMake(10, 15));
        }];
    }
    return _imgBtn;
}

- (void)actionForSubMoreBtn
{
    self.imgBtn.selected = !self.imgBtn.selected;
    self.textBtn.selected = !self.textBtn.selected;
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
